import pandas as pd
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

from get_data import get_user_num_infos

def observe_user_nums(balanceGroupbyDate):
    user_num_infos = get_user_num_infos(balanceGroupbyDate)
    plt.figure(figsize=(15, 4))
    
    plt.subplot(211)
    plt.title("用户数量动态展示")
    for k in ['累计活动用户数量','当天活动用户数量']:
        plt.bar(user_num_infos.index, user_num_infos[k], label=k)
    plt.legend()
    plt.subplot(212)
    for k in ['当天新增用户数量','当天丢失用户数量']:
        plt.bar(user_num_infos.index, user_num_infos[k], label=k)
    plt.legend()
    plt.show()


def plot_total_P_R_amt(balance_bydate: pd.DataFrame):
    plot_balance_bydate(balance_bydate,['total_purchase_amt','total_redeem_amt'],'每天的存入取出量')

def plot_total_balance_amt(balance_bydate: pd.DataFrame):
    plot_balance_bydate(balance_bydate,['tBalance','yBalance'],'每天的现存总量')

def plot_balance_bydate(balance_bydate,columns,title='',separate = False):
    if separate:
        plt_n = len(columns)
        plt.figure(figsize=(15, 2*plt_n))
        for i,coln in enumerate(columns):
            plt.subplot(plt_n,1,i+1)
            plt.plot(balance_bydate['datetime'], balance_bydate[coln],label = coln)
            plt.title(title)
            plt.legend()
    else:
        plt.figure(figsize=(15, 2))
        for coln in columns:
            plt.plot(balance_bydate['datetime'], balance_bydate[coln],label = coln)
        plt.title(title)
        plt.legend()
    plt.show()
